package com.heo.music.player.handler;

import com.heo.music.player.dto.base.BadRequestMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 星天无极
 **/
@ControllerAdvice
@Slf4j
@Order
public class SysExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResponseEntity<BadRequestMsg> runtimeExceptionHandler(Exception e) {
        log.error("系统异常", e);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                             .body(new BadRequestMsg("系统异常", e.getMessage()));
    }
}
